using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Task.Contracts;
using Task;
using DataAccess;
using Presentation.Contracts;

namespace Presentation
{
    public sealed class ShowProfilePresenter
    {
        private IShowProfileView view;

        private ISecurityTask sct;
        private ForumTask ft;
        private CommentTask ct;
        private FriendsTask frt;
        private ArtTask at;
        private GalleryTask gt;

        private user u;

        public ShowProfilePresenter(IShowProfileView view)
        {
            this.view = view;
            sct = new SecurityTask();
            ft = new ForumTask();
            ct = new CommentTask();
            frt = new FriendsTask();
            at = new ArtTask();
            gt = new GalleryTask();

            u = sct.GetUserById(view.UserId.ToString());

            at.GetBestRatedForUser(u.id, 10);
        }

        public bool hasAvatar()
        {
            return u.avatar_mime != null;
        }

        public void fillUserData()
        {

            view.Login = u.login;
            view.FirstName = u.name;
            view.LastName = u.surname;
            view.Gg = u.gg;
            view.Skype = u.skype;
            view.Email = u.email;
            

        }

        public void fillUserForums()
        {
			List<forum> tmpList= ft.GetForumsByNewestCommentForUser(0, 10000, view.UserId);
			tmpList.AddRange(ft.GetOwnedForums(0,10000,view.UserId));
            view.Forums = tmpList;
        }

        public void fillUserComments()
        {

            IList<comment> res = ct.FindLastArtCommentsForUser(view.UserId, 10);

            view.Comments = res;
        }

        public void fillUserFriends()
        {
            view.Friends = frt.GetFriendsForUser(view.UserId, 10000);
        }

        public void fillBestRated()
        {
            IList br = at.GetBestRatedForUser(view.UserId, 5);
            view.BestRated = br;
        }

        public void fillLastAdded()
        {
            view.LastAdded = at.GetLastArtForUser(view.UserId, 5);
        }

        public void fillGalleries()
        {
            view.Galleries = gt.ReadGalleriesByUserId(view.UserId);
        }

        public void sendInvitation(int fromUser)
        {
            frt.SendInvitationToFriend(fromUser, u.id);
        }
    }
}
